package com.shop.service.impl;

import com.github.pagehelper.PageInfo;
import com.shop.entity.OrderItem;
import com.shop.mapper.OrderItemMapper;
import com.shop.service.OrderItemService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("orderItemService")
@RequiredArgsConstructor
@Transactional(rollbackFor = RuntimeException.class,
        propagation = Propagation.REQUIRED)
public class OrderItemServiceImpl implements OrderItemService {
    private final OrderItemMapper orderItemMapper;

    @Override
    public PageInfo<OrderItem> listOrderItem(Integer pageNum, Integer pageSize) {
        List<OrderItem> orderItems = orderItemMapper.listOrderItem(pageNum, pageSize);
        return new PageInfo<>(orderItems);
    }

    @Override
    public OrderItem OrderItem(Integer id) {
        return orderItemMapper.OrderItems(id);
    }

    @Override
    public void addOrderItem(Integer orderId, Integer productId, Integer quantity, Double price) {
        orderItemMapper.addOrderItem(orderId, productId, quantity, price);
    }

    @Override
    public void updateOrderItem(Integer id, Integer quantity, Double price) {
        orderItemMapper.updateOrderItem(id, quantity, price);
    }

    @Override
    public void deleteOrderItem(Integer id) {
        orderItemMapper.deleteOrderItem(id);
    }

}
